package com.mj.text;

import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.comparator.Comparators;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author：作者姓名
 * @Package：com.mj.text
 * @Project：g6_jdk1.8tz
 * @name：Statstwo
 * @Date：2024/5/20 20:55
 */
@SpringBootTest
public class Statstwo {

    public static void main(String[] args) {
//        List<String> ids = Arrays.asList("101","102","103","205","308");
//
//        List<Integer> list = ids.stream().map(vv -> {
//            return Integer.parseInt(vv);
//        }).collect(Collectors.toList());
//
//
//
//        list.forEach(System.out::println);

        /**
         * map：一对多转换
         */
        List<String> list = Arrays.asList("hello world", "ni hao");

        List<String> list1 = list.stream()
                .flatMap(str -> Arrays.stream(str.split(" ")))
                .collect(Collectors.toList());


        list1.forEach(System.out::println);


        /**
         * 中间操作 filter ,sorted,distinct,limit
         */

        List<String> ids = Arrays.asList("102", "304", "34", "98", "765", "222", "222");
        List<Integer> list2 = ids.stream().filter(s -> s.length() > 2).distinct().map(Integer::valueOf)
                .sorted(Comparator.reverseOrder()) //降序
                .limit(3)
                .collect(Collectors.toList());

          list2.forEach(System.out::println);
    }


}
